package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserConsume;
import com.qinggeng.project.system.service.IUserConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户消费Controller
 *
 * @author qinggeng
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/system/consume")
public class UserConsumeController extends BaseController
{
    @Autowired
    private IUserConsumeService userConsumeService;

    /**
     * 查询用户消费列表
     */
    @PreAuthorize("@ss.hasPermi('system:consume:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserConsume userConsume)
    {
        startPage();
        List<UserConsume> list = userConsumeService.selectUserConsumeList(userConsume);
        return getDataTable(list);
    }

    /**
     * 导出用户消费列表
     */
    @PreAuthorize("@ss.hasPermi('system:consume:export')")
    @Log(title = "用户消费", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserConsume userConsume)
    {
        List<UserConsume> list = userConsumeService.selectUserConsumeList(userConsume);
        ExcelUtil<UserConsume> util = new ExcelUtil<UserConsume>(UserConsume.class);
        return util.exportExcel(list, "consume");
    }

    /**
     * 获取用户消费详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consume:query')")
    @GetMapping(value = "/{consumeId}")
    public AjaxResult getInfo(@PathVariable("consumeId") Long consumeId)
    {
        return AjaxResult.success(userConsumeService.selectUserConsumeById(consumeId));
    }

    /**
     * 新增用户消费
     */
    @PreAuthorize("@ss.hasPermi('system:consume:add')")
    @Log(title = "用户消费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserConsume userConsume)
    {
        return toAjax(userConsumeService.insertUserConsume(userConsume));
    }

    /**
     * 修改用户消费
     */
    @PreAuthorize("@ss.hasPermi('system:consume:edit')")
    @Log(title = "用户消费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserConsume userConsume)
    {
        return toAjax(userConsumeService.updateUserConsume(userConsume));
    }

    /**
     * 删除用户消费
     */
    @PreAuthorize("@ss.hasPermi('system:consume:remove')")
    @Log(title = "用户消费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consumeIds}")
    public AjaxResult remove(@PathVariable Long[] consumeIds)
    {
        return toAjax(userConsumeService.deleteUserConsumeByIds(consumeIds));
    }
}
